home *** CD-ROM | disk | FTP | other *** search
- #include "SystemSoft.h"
- /* EnumerateNameRegistry.c */
- /*
- * EnumerateNameRegistry.c
- *
- * Store the Name Registry into a two-level TwistDown list. The primary list has
- * the path name and property name concatenated. Each element has a secondary list
- * containing the element data. For example, suppose that the registry has the form:
- * Path A
- * First Property
- * First Property's Value
- * Second Property
- * Second Property's Value
- * Path B
- * First Property
- * First Property's Value
- * Second Property
- * Second Property's Value
- * The resulting registry (REG) list will look like this:
- * Path A : First Property
- * First Property's Value
- * Path A : Second Property
- * Second Property's Value
- * Path B : First Property
- * First Property's Value
- * Path B : Second Property
- * Second Property's Value
- * If this is then sorted on property (as opposed to the default of path), we get:
- * First Property
- * Path A
- * First Property's Value
- * Path B
- * First Property's Value
- * Second Property
- * Path A
- * First Property's Value
- * Path B
- * First Property's Value
- */
- #include "DisplayNameRegistry.h"
-
- void EnumeratePropertiesForThisName(
- register BrowserPtr browserPtr,
- RegEntryID *entryID,
- UInt32 regEntrySequence,
- const RegCStrPathName *pathName
- );
- OSErr StoreThisDatum(
- register BrowserPtr browserPtr,
- UInt32 regEntrySequence,
- const RegCStrPathName *pathName,
- const RegPropertyNameBuf foundProperty,
- RegPropertyModifiers propertyModifiers,
- RegPropertyValueSize propertySize,
- const void *propertyValue
- );
- Boolean CheckForUserAbort(void);
-
- /*
- * This is adapted from the sample in the 8/3/94 PCI Drivers draft. Enumerate all
- * paths and all propeties for each path. Store the entire collection in a sibling set
- * stored in the Browser Record. The list will be then sorted and broken into primary
- * and secondary sort keys according to the user's menu selection. On exit,
- * BROWSER.registrySiblingSet.firstElement is the head of the list.
- */
- void
- EnumerateNameRegistry(
- BrowserPtr browserPtr
- )
- {
- OSErr status;
- RegEntryIter cookie;
- Boolean done;
- RegEntryIterationOp op;
- RegEntryID entry;
- RegCStrPathName *pathName;
- RegPathNameSize pathNameSize;
- UInt32 regEntrySequence;
-
- NewTwistDownSiblingSet(®);
- op = kRegIterContinue;
- regEntrySequence = 0;
- status = RegistryEntryIterateCreate(&cookie);
- CheckError(status, "\pRegistryEntryIterateCreate");
- if (status == noErr) {
- done = FALSE;
- while (status == noErr && done == FALSE) {
- if (CheckForUserAbort())
- break;
- status = RegistryEntryIterate(&cookie, op, &entry, &done);
- CheckError(status, "\pRegistryEntryIterate");
- if (status == noErr && done == FALSE) {
- pathName = NULL;
- status = RegistryEntryToPathSize(&entry, &pathNameSize);
- CheckError(status, "\pRegistryEntryToPathSize");
- if (status == noErr) {
- pathName = (RegCStrPathName *) NewPtr(pathNameSize);
- if (pathName == NULL)
- status = MemError();
- }
- if (status == noErr) {
- status = RegistryCStrEntryToPath(&entry, pathName, pathNameSize);
- CheckError(status, "\pRegistryCStrEntryToPath");
- }
- if (status == noErr) {
- ++regEntrySequence; /* Increment before using */
- EnumeratePropertiesForThisName(
- browserPtr, &entry, regEntrySequence, pathName);
- }
- if (pathName != NULL)
- DisposePtr((Ptr) pathName);
- RegistryEntryIDDispose(&entry);
- }
- }
- RegistryEntryIterateDispose(&cookie);
- }
- }
-
- /*
- * EnumeratePropertiesForThisName finds all properties for the current path. It creates
- * a new registry list element (path : property) and a sub-list for the property values.
- */
- void
- EnumeratePropertiesForThisName(
- register BrowserPtr browserPtr,
- RegEntryID *entryID,
- UInt32 regEntrySequence,
- const RegCStrPathName *pathName
- )
- {
- OSErr status;
- RegPropertyIter cookie;
- Boolean done;
- RegPropertyNameBuf foundProperty;
- RegPropertyValueSize propertySize;
- RegPropertyModifiers propertyModifiers;
- void *propertyValue;
-
- #ifdef SYSF
- if ((strncmp(WECARE, pathName, strlen(WECARE)) != 0) && // "Devices:device-tree:bandit:ti1130"
- (strncmp(WECARED, pathName, strlen(WECARE)) != 0) ) // "Devices:device-tree:bandit:pci104c"
- return;
- #endif
-
- status = RegistryPropertyIterateCreate(entryID, &cookie);
- CheckError(status, "\pRegistryPropertyIterateCreate");
- if (status == noErr) {
- done = FALSE;
- while (status == noErr && done == FALSE) {
- status = RegistryPropertyIterate(&cookie, foundProperty, &done);
- CheckError(status, "\pRegistryPropertyIterate");
- if (status == noErr && done == FALSE) {
- propertyValue = NULL;
- status = RegistryPropertyGetSize(
- entryID, foundProperty, &propertySize);
- CheckError(status, "\pRegistryPropertyGetSize");
- if (status == noErr) {
- propertyValue = NewPtr(propertySize);
- if (propertyValue == NULL) {
- status = MemError();
- NonFatalError(status, "\pNo memory to store property");
- }
- }
- if (status == noErr) {
- status = RegistryPropertyGet(
- entryID,
- foundProperty,
- propertyValue,
- &propertySize
- );
- CheckError(status, "\pRegistryPropertyGet");
- }
- if (status == noErr) {
- status = RegistryPropertyGetMod(
- entryID,
- foundProperty,
- &propertyModifiers
- );
- CheckError(status, "\pRegisteryPropertyGetMod");
- }
- if (status == noErr) {
- status = StoreThisDatum(
- browserPtr,
- regEntrySequence,
- pathName,
- foundProperty,
- propertyModifiers,
- propertySize,
- propertyValue
- );
- if (status != noErr)
- NonFatalError(status, "\pCould not store property");
- }
- if (propertyValue != NULL)
- DisposePtr((Ptr) propertyValue);
- }
- }
- RegistryPropertyIterateDispose(&cookie);
- }
- }
-
- /*
- * StoreThisDatum stores a path : property : value in the list. Registry list elements
- * are always locked in memory. The path + property is stored as two concatenated
- * C-strings. This is the only routine that constructs a registry list element.
- */
- OSErr
- StoreThisDatum(
- register BrowserPtr browserPtr,
- UInt32 regEntrySequence,
- const RegCStrPathName *pathName,
- const RegPropertyNameBuf foundProperty,
- RegPropertyModifiers propertyModifiers,
- RegPropertyValueSize propertySize,
- const void *propertyValue
- )
- {
- OSErr status;
- unsigned long totalNameSize;
- short pathNameSize;
- short foundPropertySize;
- #define ELEM (**REG.thisElement)
-
- /*
- * The name is stored as two concatenated C strings:
- * path EOS property EOS preceeded the binary sequence number.
- */
- pathNameSize = strlen(pathName);
- foundPropertySize = strlen(foundProperty);
- totalNameSize = sizeof regEntrySequence + pathNameSize + 1 + foundPropertySize + 1;
- status = MakeTwistDownSibling(®, 0, totalNameSize, NULL);
- if (status == noErr) {
- MoveHHi((Handle) REG.thisElement);
- HLock((Handle) REG.thisElement); /* Locked from now on */
- if ((propertyModifiers & kRegPropertyValueIsSavedToNVRAM) != 0)
- ELEM.flag |= kSavedInNVRAM;
- if ((propertyModifiers & kRegPropertyValueIsSavedToDisk) != 0)
- ELEM.flag |= kSavedOnDisk;
- BlockMoveData(
- ®EntrySequence,
- &ELEM.data[0],
- sizeof regEntrySequence
- );
- BlockMoveData(
- pathName,
- &ELEM.data[sizeof regEntrySequence],
- pathNameSize
- );
- /*
- * Terminate the path name string.
- */
- ELEM.data[pathNameSize + sizeof regEntrySequence] = '\0';
- BlockMoveData(
- foundProperty,
- &ELEM.data[sizeof regEntrySequence + pathNameSize + 1],
- foundPropertySize
- );
- ELEM.data[totalNameSize - 1] = '\0'; /* End of property string */
- if (propertySize > 0) { /* Property in sub-list */
- /*
- * This will always create a sub-list. If the sub-list has a single
- * element, and it's short enough, the display module will scrunch
- * the secondary key and the data onto a single line of text.
- */
- ELEM.flag |= kHasTwistDown;
- ELEM.subElement = FormatThisProperty(
- foundProperty,
- propertySize,
- propertyValue
- );
- }
- }
- return (status);
- #undef ELEM
- }
-
- /*
- * You must lock down the element before calling this routine. This is the only
- * routine that unpacks a registry element. This function returns the registry
- * entry sequence id that is needed to disambiguate between different entries
- * with identical entry names.
- */
- UInt32
- UnpackDataRecord(
- const TwistDownPtr thisElement, /* Locked TwistDownHdl */
- char **pathNameCString,
- char **foundPropertyCString
- )
- {
- #define ELEM (*thisElement)
- UInt32 result;
-
- BlockMoveData(&ELEM.data[0], &result, sizeof result);
- *pathNameCString = (char *) &ELEM.data[sizeof result];
- *foundPropertyCString =
- (char *) &ELEM.data[sizeof result + strlen(*pathNameCString) + 1];
- return (result);
- #undef ELEM
- }
-
- Boolean
- CheckForUserAbort(void)
- {
- EventRecord currentEvent;
- Boolean result;
-
- EventAvail(everyEvent, ¤tEvent);
- SpinCursor();
- result = FALSE;
- if ((currentEvent.what == keyDown || currentEvent.what == autoKey)
- && (currentEvent.modifiers & cmdKey) != 0
- && (currentEvent.message & keyCodeMask) == '.')
- result = TRUE;
- return (result);
- }
-
-